<?php


class EvenementTable extends Doctrine_Table {

    public static function getInstance() {
        return Doctrine_Core::getTable('Evenement');
    }

    public static function getEvenementParInterval($start, $end) {
        if (is_null($start) || is_null($end)) {
            $events = $this->findAll();
        } else {
            $query = new Doctrine_Query();
            $query->from('Evenement e')
                    ->addWhere('e.date > ', $start)
                    ->orWhere ('e.date = ', $start)
                    ->andWhere('e.date < ', $end)
                    ->orWhere ('e.date = ', $end);
            $events = $query->execute();
        }

        return $events;
    }

    public static function supprimerSeancesStage($stageId, $date) {
        if (!is_null($stageId) && !is_null($date)) {
            self::getInstance()->createQuery()
                    ->delete()
                    ->where('id_stage = ?', $stageId)
                    ->andWhere('date >= ?', $date)
                    ->execute();
        } else {
            throw new Exception("stage->getId() or date might be null");
        }
    }

    public static function supprimerRepresentationSpectacle($spectacleId, $date) {

        if (!is_null($spectacleId) && !is_null($date)) {
            self::getInstance()->createQuery()
                    ->delete()
                    ->where('id_spectacle = ?', $spectacleId)
                    ->andWhere('date >= ?', $date)
                    ->execute();
        } else {
            throw new Exception("spectacle->getId() or date might be null");
        }
    }

    
}